package com.example.smart_city_0829.activity.sdkm;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.DeathData;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.base.CommonAdapter;
import com.example.smart_city_0829.entity.sdkm.Kmlb;

public class SbdyxActivity extends BaseActivity {

    private Button add;
    private ListView lv;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sbdyx;
    }

    @Override
    protected void initView() {
        add = (Button) findViewById(R.id.add);
        lv = (ListView) findViewById(R.id.lv);
    }

    @Override
    protected void initData() {
        lv.setAdapter(new CommonAdapter<Kmlb,CommonAdapter.CommListViewHolder>(
                DeathData.sbdyx,
                SbdyxActivity.this
        ) {
            @Override
            protected void setData(Kmlb data, int position, CommListViewHolder viewHolder, View convertView, Context context) {
                Glide.with(context)
                        .load(data.getPic())
                        .into(viewHolder.im);
                viewHolder.title.setText(data.getTitle());
                viewHolder.content.setText(data.getContent());
                viewHolder.tag3.setText(data.getName());
            }

            @Override
            protected CommListViewHolder getViewHolder() {
                return new CommListViewHolder();
            }

            @Override
            protected void initView(CommListViewHolder viewHolder, View convertView) {
                viewHolder.title = (TextView) convertView.findViewById(R.id.title);
                viewHolder.im = (ImageView) convertView.findViewById(R.id.im);
                viewHolder.content = (TextView) convertView.findViewById(R.id.content);
                viewHolder.tag1 = (TextView) convertView.findViewById(R.id.tag1);
                viewHolder.tag2 = (TextView) convertView.findViewById(R.id.tag2);
                viewHolder.tag3 = (TextView) convertView.findViewById(R.id.tag3);
            }
        });
    }

    @Override
    protected void initEvent() {
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SbdyxActivity.this, AddContentActivity.class);
                intent.putExtra("type",3);
                startActivity(intent);
            }
        });
    }

    @Override
    protected String getActionBarTitle() {
        return "身边的英雄";
    }
}